package cn.yunhe.action;

import cn.yunhe.entity.Users;
import cn.yunhe.service.UserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ModelDriven;

import java.io.PrintWriter;

public class loginAction extends BaseAction implements ModelDriven<Object> {
    private Users users;

    @Override
    public String execute() throws Exception {
        UserService userService = new UserService();
        Users user = userService.getNewsByUp(users);
          if(user!=null){
                int  user1 = user.getUserId();
             getSession().setAttribute("user1",user1);
                System.out.println(user1);
              return SUCCESS;
          }else {
             PrintWriter  out =getResponse().getWriter();
             out.print("<script>alert('账号或者密码错误');</script>");
         return  null;
          }
            }

    public Users getUsers() {
        return users;
    }

    public void setUsers(Users user) {
        this.users = users;
    }

    @Override
    public Object getModel() {
        if(users==null){
            users= new Users();
        }
        return  users;
    }
}
